<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的社区</title>
    <script src="js/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/community.css">
    <script src="js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">我的社区</span>
            </button>
            <a class="navbar-brand" href="#">我的社区</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="搜索话题">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a class="goToPublish">发起</a>
                </li>
                <li th:if="${session.user == null}">
                    <!--TODO: 开发期间暂时不通过GitHub登录-->
                    <!--                    <a href="https://github.com/login/oauth/authorize?client_id=b675661f86d5de20d997&redirect_uri=http://localhost:8888/callback&scope=user&state=1">登录</a>-->
                    <a href="/user/login">登录</a>
                </li>
                <li class="dropdown" th:unless="${session.user == null}">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false"><img height="30" width="30" th:src="${session.user.getAvatarUrl()}" alt=""><span
                            class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">消息中心</a></li>
                        <li><a href="#">个人资料</a></li>
                        <li><a href="/user/logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="container-fluid main">
    <div class="row">
        <div class="col-lg-9 col-md-12 col-sm-12">
            <h2><span class="glyphicon glyphicon-list" aria-hidden="true"></span>发起</h2>
            <hr>
            <div class="media" th:each="question : ${questions}">
                <div class="media-left">
                    <a href="#">
                        <img class="media-object" th:src="${question.user.avatarUrl}" alt="">
                    </a>
                </div>
                <div class="media-body">
                    <h4 class="media-heading" th:text="${question.title}"></h4>
                    <span th:text="${question.description}"></span> <br>
                    <span class="text-desc"><span
                            th:text="${question.commentCount}"></span> 个回复 • <span
                            th:text="${question.viewCount}"></span>次浏览 • <span
                            th:text="${#dates.format(question.gmtCreate, 'yyyy-MM-dd')}"></span></span>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-12 col-sm-12">
            <h3>热门话题</h3>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(".goToPublish").click(function () {
        $.ajax({
            url: "/user/getUserIsLogin",
            type: "get",
            data: null,
            success: function (data) {
                if (data != null) {
                    if (data.status != 200) {
                        //未登录
                        alert(data.msg);
                    } else {
                        //已登录
                        location.href = "/publish";
                    }
                }
            }

        })
    });
</script>
</html>